package com.lg.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lg.entity.UserInfo;
import com.lg.pojo.Result;
import com.lg.repositories.UserInfoRepository;

@RestController
public class Mycontroller {
    @Autowired
	private UserInfoRepository userInfoRepository;
	
	@PostMapping("/login")
	public  void  ss(String username,String password ) {
		Subject subject = SecurityUtils.getSubject();
		AuthenticationToken token = new UsernamePasswordToken(username, password);
		subject.login(token );
		boolean authenticated = subject.isAuthenticated();
	}
	
	@PostMapping("/registe")
	public  Result  registe(UserInfo userInfo) {
	
		try {
			userInfoRepository.save(userInfo);
		return	Result.build().setBody("success").setCode("200").setIsSucess(true);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			return	Result.build().setBody("false").setCode("200").setIsSucess(false);
		}
		
	}
}
